
// 参考:https://cloud.tencent.com/developer/article/1173764

#include <iostream>
#include <cstdio>
#include <memory>
#include <functional>

class button
{
public:
    button(std::string t_title = "default"): m_title(t_title) {

    }

    ~button() {

    }

    std::string title() {
        return m_title;
    }

    std::function<void(int)> onClick;

private:
    std::string m_title;
};

class player
{
public:

    void play(void* sender, int param) {
        button* a = static_cast<button *>(sender);
        std::cout << a->title(); 
        printf(" clicked => %d\n", param);
    };
    void stop(void* sender, int param) {
        button* a = static_cast<button *>(sender);
        std::cout << a->title(); 
        printf(" clicked => %d\n", param);
    };
};

button playButton = button("play");
button stopButton = button("stop");
player thePlayer;

void connect()
{
    playButton.onClick = std::bind(&player::play, &thePlayer, &playButton, std::placeholders::_1);
    stopButton.onClick = std::bind(&player::stop, &thePlayer, &stopButton, std::placeholders::_1);
}

int main () {
    connect();
    playButton.onClick(0);
    stopButton.onClick(1);
    return 0;
}